package mortal.game.control
{
    import modules.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class NoviceCardController extends Controller
    {
        private var _noviceCard:NoviceCardModule;
        private var _cardType:int;
        private var _cardName:String;

        public function NoviceCardController()
        {
            
        }

        override protected function initView() : IView
        {
            this._noviceCard = new NoviceCardModule();
            return this._noviceCard;
        }

        override protected function initServer() : void
        {
            Dispatcher.addEventListener(EventName.NoviceCardOpen, this.onNoviceCardOpenHandler);
            Dispatcher.addEventListener(EventName.NovicePackGet, this.onNovicePackGetHandler);
            Dispatcher.addEventListener(EventName.NoviceCardUse, this.onNoviceCardUseHandler);
            Dispatcher.addEventListener(EventName.NoviceCardUseSuccess, this.onNoviceCardUseSuccessHandler);
            Dispatcher.addEventListener(EventName.NoviceCardUseFail, this.onNoviceCardUseFailHandler);
            
        }

        private function onNoviceCardOpenHandler(event:DataEvent) : void
        {
            if (view == null)
            {
                this.initView();
            }
            view.show();
            
        }

        private function onNovicePackGetHandler(event:DataEvent) : void
        {
            var _loc_2:* = event.data as int;
            var _loc_3:String = "000000000000";
            this._cardName = PromotionCardConfig.instance.getCardNameByType(_loc_2);
            GameProxy.noviceCardProxy.useNoviceCard(_loc_2, _loc_3);
            
        }

        private function onNoviceCardUseHandler(event:DataEvent) : void
        {
            var _loc_2:* = event.data as Object;
            this._cardType = _loc_2.type;
            this._cardName = PromotionCardConfig.instance.getCardNameByType(this._cardType);
            GameProxy.noviceCardProxy.useNoviceCard(this._cardType, _loc_2.key);
            
        }

        private function onNoviceCardUseSuccessHandler(event:DataEvent) : void
        {
            view.hide();
            MsgManager.addBroadCast("成功领取" + this._cardName + "礼包");
            
        }

        private function onNoviceCardUseFailHandler(event:DataEvent) : void
        {
            if (this._noviceCard != null)
            {
                this._noviceCard.resetModule();
            }
            var _loc_2:* = event.data as int;
            var _loc_3:String = "";
            if (_loc_2 == 35600)
            {
                _loc_3 = this._cardName + "类型错误";
            }
            else if (_loc_2 == 35601)
            {
                if (this._cardName == "首充礼包")
                {
                    _loc_3 = "您还没有充值";
                }
                else
                {
                    _loc_3 = this._cardName + "非法";
                }
            }
            else if (_loc_2 == 35602)
            {
                _loc_3 = this._cardName + "已被使用";
            }
            else if (_loc_2 == 35603)
            {
                _loc_3 = "您已领取过" + this._cardName;
            }
            else if (_loc_2 == 35340)
            {
                _loc_3 = "背包已满";
            }
            MsgManager.addBroadCast(_loc_3);
            
        }

    }
}
